package schedule.way_quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

public class QuartzTask {
    public static void main(String[] args) throws SchedulerException {
        runQJob();
    }

    private static void runQJob() throws SchedulerException {
        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();

        JobDetail detail = JobBuilder.newJob(QJob.class)
                .withDescription("this is a simple job")
                .withIdentity("simpleJob", "jobGroup")
                .build();

        long time = System.currentTimeMillis() + 2000L;
        Date date = new Date(time);

        Trigger trigger = TriggerBuilder.newTrigger()
                .withDescription("des")
                .withIdentity("simpleJobB", "jobGroupB")
                .startAt(date)
                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?"))
                .build();

        scheduler.scheduleJob(detail, trigger);
        scheduler.start();

    }


    /**
     * 具体任务逻辑
     */
    private class QJob implements Job {
        private int count = 0;

        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
            JobDetail detail = context.getJobDetail();
            System.out.println("count is:" );
        }
    }
}
